﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Linq;
using System.IO;
using Com.CodePlex.SPPower.Data;
using Com.CodePlex.SPPower.Controller;
using Com.CodePlex.SPPower.Model;
using System.Windows.Input;
using System.Net.NetworkInformation;
using System.Text;
//using Com.CodePlex.SPPower.View; //should not reference this http://social.msdn.microsoft.com/Forums/is/wpf/thread/3bced3ea-4a97-4456-bfe5-828289bcf971

namespace Com.CodePlex.SPPower.ViewModel {

	public class CmdCategoryViewModel : LazyChildrenViewModel {

        private CmdCategory item;

        public CmdCategoryViewModel(CmdCategory item, CmdCategoryViewModel parent)
            : base(parent) {
            this.item = item;
            DisplayName = item == null ? "No Category" : item.Name;
            Mediator.Register(this);
            //note: lazy load: dont do more stuff here
        }

		#region Display Properties

		private bool isselected;
		public bool IsSelected {
			get { return isselected; }
			set {
				if (value != isselected) {
					isselected = value;
					OnPropertyChanged(() => IsSelected);
				}
			}
		}

		public string ImageSource {
			get { return "pack://application:,,,/Resources/Images/Folder.jpg"; }
		}

		#endregion

		protected override void Load() {
            if (item != null) {
                new CmdRepository().FindCategoryItems(item)
                    .ToList()
                    .ForEach(i => {
                        if (i is CmdCategory) {
                            Children.Add(new CmdCategoryViewModel((CmdCategory)i, this));
                        } else {
                            Children.Add(new CmdViewModel((Cmd)i, this));
                        }
                    });
            }
		}
	}
}